﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace WJP.ComponentModel
{
    /// <summary>
    /// 从指定的类型加载程序集插件
    /// </summary>
    public class TypeListPluginSource : PluginSourceBase
    {
        private readonly Type[] _pluginTypes;

        public TypeListPluginSource(params Type[] pluginTypes)
        {
            foreach (var type in pluginTypes)
            {
                if (!PluginBase.IsPlugin(type))
                    throw new Exception("插件类型必须继承自IPlugin");
            }
            _pluginTypes = pluginTypes;
        }

        public override List<Type> GetPlugins()
        {
            return _pluginTypes.ToList();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override List<Assembly> LoadAssemblies()
        {
            return _pluginTypes.Select(type => type.GetTypeInfo().Assembly).ToList();
        }
    }
}
